package com.sise.cn.api.common.impl;

import com.sise.cn.api.common.po.Order;
import com.sise.cn.api.common.service.OrderService;
import com.sise.cn.dao.base.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/14 16:16
 * 订单的默认实现接口
 */
@Service
@Slf4j
@ConditionalOnMissingBean(OrderService.class)
public class OrderServiceImpl implements OrderService {
    @Resource
    private BaseMapper baseMapper;

    @Override
    public Order getOrderById(Long id) {
        final Order order = new Order();
        order.setId(id);
        return baseMapper.select(order, Order.class);
    }

    @Override
    public Long saveOrder(Order order) {
        return baseMapper.insertAndGetId(order);
    }

    @Override
    public List<Order> getOrderByOrderCode(String orderCode) {
        final Order order = new Order();
        order.setOrderCode(orderCode);
        return baseMapper.selectList(order, Order.class);
    }

    @Override
    public void updateOrderByOrderCode(Order order) {
        baseMapper.update(order);
    }

    @Override
    public void deleteOrderById(Long id) {
        final Order order = new Order();
        order.setId(id);
        baseMapper.delete(order);
    }

}
